You can integrate the Ditto SDK into Kotlin projects to develop for the Android platform.
minSdk
version 23
compileSdk
version 34
build.gradle
file in the dependencies
block with the appropriate version:
AndroidManifest.xml
To override any of these permission limitations in your app, do the following:
AndroidManifest.xml
located in the app/src/main
directory of your project.<manifest>
tag, just before the <application>
tag, add the relevant permissions you want to configure (location example):tools:remove
attribute. This tells the manifest merger to selectively remove the android:maxSdkVersion
behavior from the associated permissions, changing them to apply to all Android versions.DittoSyncPermissions
helper class:
DittoSyncPermissions
helper class in the main activity of your app:Activity
or Fragment’s onCreate
method:refreshPermissions()
on your Ditto instance to quickly check and start syncing with the new permissions. This can be done in the onRequestPermissionsResult()
activity lifecycle method:Context
, integrate Ditto into your app’s onCreate
method.
Most apps require that Ditto run as a singleton. A singleton is an implementation ensuring your Ditto instance accesses and shares a single object instance throughout your app.
To store the Ditto instance as a singleton object, create a custom Application
subclass for your Android app. Include the necessary setup configuration below in the onCreate
method.
Application.onCreate
method.Context
instead of the Context
from any activity where you initially instantiated the Ditto instance.YOUR_APP_ID
and YOUR_PLAYGROUND_TOKEN
with your access credentials available in the portal.keep class live.ditto.internal.swig.ffi.**
ensures that all classes and interfaces under the live.ditto.internal.swig.ffi package (including sub-packages) are retained.{ *; }
specifies that all members (fields, methods, constructors, etc.) of these classes should be preserved as well.